package com.cx.jdk;

import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

/**
 * @Author:cxy
 * @Date:2020/9/13 12:22
 */
public class TestPriorityBlockingQueue {

    public static void main(String[] args) throws InterruptedException {
        //不需要排序   取出第K大的值
        List<Integer> asList = Arrays.asList(1, 5, 2, 4, 7, 3, 9, 8);
        PriorityQueue<Integer> queue1 = new PriorityQueue<>(7);
        for (int i = 0; i < asList.size(); i++) {
            queue1.add(asList.get(i));
            if(queue1.size()>3){
                queue1.poll();//顶部最小元素出队列
            }
        }
        System.out.println(queue1.peek());
    }

}
